Page({
  /**
   * 页面的初始数据
   */
  data: {
    tabs: ['报名中', '报名结束'],
    tabIndex: 0,
    tabContents: [
      {
        items: []
      },
      {
        items: []
      }
    ]
  },

  onLoad() {
    let that = this;
    wx.request({
      url: 'http://8.138.155.196:3000/users/api/activity.list',
      method: 'GET',
      data: {},
      header: {
        'content-type': 'application/json'
      },
      success(res) {
        const unfinishedActivities = [];
        const finishedActivities = [];
        res.data.data.forEach(item => {
          if (item.Isfinsh === 0) {
            unfinishedActivities.push(item);
          } else {
            finishedActivities.push(item);
          }
        });
        that.setData({
          'tabContents[0].items': unfinishedActivities,
          'tabContents[1].items': finishedActivities
        });
      },
      fail(err) {
        console.log(err);
      }
    });
  },

  onTabClick(e) {
    let id = e.currentTarget.id;
    this.setData({
      tabIndex: id
    })
  },

  toDetail: function(e) {
    const activityId = e.currentTarget.dataset.id;
    console.log(activityId, 'guo');

    // 跳活动详情页，这里的 'activityDetail' 应替换为实际页面路径
    wx.navigateTo({
      url: `/packageB/pages/activityDetail/activityDetail?activityId=${activityId}`
    });
  }
})
